package vaccine.appointment.system.vaccinationsite.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vaccine.appointment.system.common.annotation.AutoWrapResult;
import vaccine.appointment.system.common.annotation.RequireRole;
import vaccine.appointment.system.user.enums.IdentityInfoEnum;
import vaccine.appointment.system.vaccinationsite.service.VaccinationSiteService;
import vaccine.appointment.system.vaccinationsite.vo.AddVaccinationSiteRequest;
import vaccine.appointment.system.vaccinationsite.vo.UpdateVaccinationSiteRequest;
import vaccine.appointment.system.vaccinationsite.vo.VaccinationSiteVO;

import javax.validation.Valid;
import java.util.List;

/**
 * 管理员接种点控制器
 */
@AutoWrapResult
@RequestMapping("/admin/vaccination-site")
@RestController
@RequireRole(IdentityInfoEnum.SUPER_ADMIN)
public class AdminVaccinationSiteController {

    @Autowired
    private VaccinationSiteService vaccinationSiteService;

    /**
     * 添加接种点
     * @param request 添加接种点请求
     * @return 是否成功
     */
    @PostMapping("")
    public Boolean addSite(@Valid @RequestBody AddVaccinationSiteRequest request) {
        return vaccinationSiteService.addSite(request);
    }

    /**
     * 更新接种点
     * @param siteId 接种点ID
     * @param request 更新接种点请求
     * @return 是否成功
     */
    @PutMapping("/{siteId}")
    public Boolean updateSite(
            @PathVariable Integer siteId,
            @Valid @RequestBody UpdateVaccinationSiteRequest request) {
        return vaccinationSiteService.updateSite(siteId, request);
    }

    /**
     * 删除接种点
     * @param siteId 接种点ID
     * @return 是否成功
     */
    @DeleteMapping("/{siteId}")
    public Boolean deleteSite(@PathVariable Integer siteId) {
        return vaccinationSiteService.deleteSite(siteId);
    }

    /**
     * 查询接种点列表
     * @return 接种点列表
     */
    @GetMapping("/list")
    public List<VaccinationSiteVO> getVaccinationSiteList() {
        return vaccinationSiteService.getAllSites();
    }
}

